package mvp.com.register.presenter;

import android.os.Handler;

import mvp.com.register.model.ISplashBiz;
import mvp.com.register.model.impl.SplashBiz;
import mvp.com.register.view.ISplashView;

/**
 * Created by Administrator on 2016/9/17 0017.
 */
public class SplashPresenter {

    ISplashView splashView;
    ISplashBiz splashBiz;
    Handler handler = new Handler();

    public SplashPresenter(ISplashView splashView) {
        this.splashView = splashView;
        this.splashBiz = new SplashBiz();
    }

    public void splash() {

        splashBiz.splash(new ISplashView.OnSplashListener() {
            String msg = "连接网络错误！";
            String upMsg = "有版本更新！";

            @Override
            public void newVersion() {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        splashView.showDialog(upMsg);
                    }
                });
            }

            @Override
            public void success() {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        splashView.toMain();
                        splashView.finishAs();
                    }
                });

            }

            @Override
            public void error() {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        splashView.showToast(msg);
                    }
                });
            }
        });

    }
}
